﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace GameBoard
{
    [DataContract]
    public class ObjectVisualData : BaseTerrainData
    {
        public ObjectVisualData()
        {
            
        }

        [DataMember]
        public string ObjectFile { get; set; }

        public System.Windows.Media.Media3D.RotateTransform3D RotateTransform 
        {
            get
            {
                var rotateTransform = 
                    new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), Angle));
                return rotateTransform;
                
            }
        }
        public System.Windows.Media.Media3D.ScaleTransform3D ScaleTransform
        {
            get
            {
                var scaleTransform = new ScaleTransform3D(Scale, Scale, Scale);
                return scaleTransform;

            }
        }
        public override Material Material
        {
            get
            {
                if (!String.IsNullOrWhiteSpace(MaterialFile))
                {
                    var imageBrush = MaterialMaker.MakeImageMaterial(MaterialFile);
                    return new DiffuseMaterial(imageBrush);
                }
                return new DiffuseMaterial(new SolidColorBrush(MaterialColor));
            }
        }

        public System.Windows.Media.Media3D.TranslateTransform3D TranslateTransform {

            get
            {
                var translateTransform = new TranslateTransform3D(_centerOfTerrainFeature.X, _centerOfTerrainFeature.Y, _centerOfTerrainFeature.Z + VerticalPosition);
                return translateTransform;
            }
        }
        [DataMember]
        private Point3D _centerOfTerrainFeature = new Point3D();
        
        public override Point3D CenterOfTerrainFeature
        {
            get
            {
                return _centerOfTerrainFeature;
            }
        }
        public override string ItemDescription
        {
            get
            {
                return Path.GetFileNameWithoutExtension(ObjectFile);
            }
        }
        public override double ZoomHeight
        {
            get
            {
                return 80;
            }
        }

        [DataMember]
        public double Angle { get; set; }

        [DataMember]
        public double Scale { get; set; }

        public Point3D ObjectCenter
        {
            set
            {
                _centerOfTerrainFeature = value;
            }
        }
        
        [DataMember]
        public double VerticalPosition { get; set; }
    }
}
